<?php
namespace Admin\Controller;

use Think\Controller;

// 需要登录才能访问的
class SignInController extends BaseController
{
    Public function _initialize(){

        parent::_initialize();

        // 没有登录
        $account = $this->getAccount();
        if(empty($account)){
            die("<script>window.parent.location.href = '" . U("Admin/Login/index") ."';</script>");
        }

        // 存入账号信息
        $this->assign("account", $account);
    }

    // 获取账号信息
    function getAccount(){
        // 获取token
        return $this->get('admin');
    }

    // 获取账号ID
    function getAccountId(){
        return $this->getAccount()['id'];
    }

    // 获取下拉框
    function getRoleList($rolePathP = '', $rolePath = '')
    {
        // 如果不传参数就从登陆人获取
        if (empty($rolePathP)) {
            $roleList = M('page')->where(array("isUsed"=>0))->select();
        } else {
            $roleList = M('page')->where(array("code" => array("IN", $rolePathP), "isUsed"=>0))->order("sort ASC")->select();
        }

        // 如果有选中状态
        if(!empty($rolePath)){
            for ($j = 0; $j < count($roleList); $j++){
                $roleList[$j]['check'] = in_array($roleList[$j]['code'], explode(',', $rolePath));
            }
        }
        return $roleList;
    }
}